package cn.monkey.state.core.reactive;

import cn.monkey.state.core.*;
import reactor.core.publisher.Mono;

import java.util.function.Supplier;

public class SimpleReactiveStateGroupFactory implements ReactiveStateGroupFactory {

    protected final Supplier<Long> timer;

    public SimpleReactiveStateGroupFactory(Supplier<Long> timer) {
        this.timer = timer;
    }

    @Override
    public Mono<StateGroup> create(String id, Object... args) {
        return Mono.create(stateGroupMonoSink -> {
            StateGroup stateGroup = new SimpleStateGroup(id, StateContext.EMPTY, this.timer);
            State state = new EmptyState(stateGroup);
            stateGroup.addState(state);
            stateGroup.setStartState(EmptyState.CODE);
            stateGroupMonoSink.success(stateGroup);
        });
    }
}
